/* eslint-disable react-hooks/rules-of-hooks */
import { useEffect, useState } from "@storybook/addons"

function userDebounce(value: any, delay = 300) {
	const [debounceValue, setDebounceValue] = useState(value)
	useEffect(() => {
		const handler = window.setTimeout(() => {
			setDebounceValue(value)
		}, delay)
		return () => {
			clearTimeout(handler)
		}
	}, [value, delay])

	return debounceValue
}

export default userDebounce
